﻿using MiniFox.Components;
using MiniFox.Infrastructure;
using MiniFox.Platform.Applications;
using MiniFox.Platform.Applications.Auth;
using MiniFox.Platform.Exceptions;
using MiniFox.Utility;
using Sys.Core.Models.Dto;
using Sys.Core.Models.Queries;
using Sys.Core.Models.VO;
using Sys.Core.Providers;

namespace Sys.Core.Services
{
    /// <summary>
    /// 
    /// </summary>
    [AutoResolve]
    public class SequenceService : ApiServiceBase, ISequenceService
    {
        public SequenceService(SystemPrincipal principal) : base(principal)
        {
        }
        [AutoWired]
        public ISequenceProvider Provider { get; set; }

        public ResultObject<IEnumerable<SequenceSetVo>> Query(PagedQueryObject<SequenceSetQuery> request)
        {
            return this.Provider.Query(request);
        }

        public SequenceSetVo Item(string name)
        {
            return this.Provider.GetItem(name);
        }

        public SequenceSetVo Create(SequenceSetDto dto)
        {
            if (!this.Provider.Create(dto))
                return null;
            return Item(dto.Name);
        }

        public SequenceSetVo Update(SequenceSetDto dto)
        {
            if (!this.Provider.Update(dto))
                return null;
            return Item(dto.Name);
        }

        public void Remove(string[] names)
        {
            if (!this.Provider.Remove(names))
                throw new PlatformException("ERR_OperateFail");
        }

        public void Reset(string[] names)
        {
            if (!this.Provider.Reset(names))
                throw new PlatformException("ERR_OperateFail");
        }
    }
}
